home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 2.5 KB | 90 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // BCDynami.h
- //
- // This file contains the declaration of the dynamic array-based class
- // used for the representation of dynamic structures.
-
- #ifndef BCDYNAMI_H
- #define BCDYNAMI_H 1
-
- #include <stddef.h>
- #include "BCExcept.h"
-
- // Class denoting an optimally-packed dynamic container
-
- template<class Item, class StorageManager>
- class BC_TDynamic {
- public:
-
- BC_TDynamic();
- BC_TDynamic(BC_Index chunkSize);
- BC_TDynamic(const BC_TDynamic<Item, StorageManager>&);
- ~BC_TDynamic();
-
- BC_TDynamic<Item, StorageManager>&
- operator=(const BC_TDynamic<Item, StorageManager>&);
- BC_Boolean operator==(const BC_TDynamic<Item, StorageManager>&) const;
- BC_Boolean operator!=(const BC_TDynamic<Item, StorageManager>& c) const
- {return !operator==(c);}
- const Item& operator[](BC_Index index) const
- {BC_Assert((index < Length()),
- BC_XRangeError("BC_TDynamic<>::operator[]", BC_kInvalidIndex));
- return ItemAt(index);}
- Item& operator[](BC_Index index)
- {BC_Assert((index < Length()),
- BC_XRangeError("BC_TDynamic<>::operator[]", BC_kInvalidIndex));
- return ItemAt(index);}
-
- void SetChunkSize(BC_Index chunkSize)
- {BC_Assert((!fChunkSize),
- BC_XNotNull("BC_TDynamic<>::SetChunkSize", BC_kNotEmpty));
- fChunkSize = chunkSize;}
- void Preallocate(BC_Index newLength);
- void Clear();
- void Insert(const Item&);
- void Insert(const Item&, BC_Index before);
- void Append(const Item&);
- void Append(const Item&, BC_Index after);
- void Remove(BC_Index at);
- void Replace(BC_Index at, const Item&);
-
- BC_Index ChunkSize() const
- {return fChunkSize;}
- BC_Index Length() const;
- const Item& First() const
- {return fRep[fStart - 1];}
- Item& First()
- {return fRep[fStart - 1];}
- const Item& Last() const
- {return fRep[fStop - 1];}
- Item& Last()
- {return fRep[fStop - 1];}
- const Item& ItemAt(BC_Index) const;
- Item& ItemAt(BC_Index);
- BC_ExtendedIndex Location(const Item&, BC_Index start = 0) const;
-
- static void* operator new(size_t);
- static void operator delete(void*, size_t);
-
- protected:
-
- Item* fRep;
- BC_Index fSize;
- BC_Index fTotalChunks;
- BC_Index fChunkSize;
- BC_Index fStart;
- BC_Index fStop;
-
- void Resize(BC_Index currentLength, BC_Index newLength, BC_Boolean preserve = 1);
-
- BC_Index ExpandLeft(BC_Index from);
- BC_Index ExpandRight(BC_Index from);
- void ShrinkLeft(BC_Index from);
- void ShrinkRight(BC_Index from);
-
- };
-
- #endif
-